package com.leyou.trade.web;


import com.baomidou.mybatisplus.extension.api.R;
import com.leyou.trade.entity.CartItem;
import com.leyou.trade.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired  //mongodb的查询接口
    private CartService cartService;


    //todo 添加到数据库 同时存进mongodb
    @PostMapping
    public ResponseEntity<Void> saveCartItem(
            @RequestBody CartItem cartItem) {

        this.cartService.saveCartItem(cartItem);

        return ResponseEntity.ok().build();

    }


    @GetMapping("/list")
    public ResponseEntity<List<CartItem>> queryCartList() {


        return ResponseEntity.ok(this.cartService.listUserCarts());

    }

 /*   @PutMapping
    public */

    //todo 删除 购物车中一项
    @DeleteMapping("{skuId}")
    public ResponseEntity<Void>deleteCart(@PathVariable("skuId") Long skuId){

        this.cartService.deleteCart(skuId);
        return ResponseEntity.noContent().build();
    }




}
